/**
 * [OElove] (C)2010-2099 OELOVE.COM Inc.biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/01/16 by CL $
*/
$(function(){
	
	//选择性别
	$("[f='but_ser_gender']").click(function(){
		$_id = $(this).attr("data-id");
		$("#s_gender").val($_id);
		$("[f='but_ser_gender']").removeClass("current");
		$(this).addClass("current");
		$("#marry_form").submit();
	});

	//搜索选择器
	$(document).on("click", "[f='but_selser']", function(){
		$_dd = $(this).next("dd");
		if ($_dd.css("display") == "none") {
			$(this).parent().addClass("current");
			$_dd.show();
		}
		else {
			$(this).parent().removeClass("current");
			$_dd.hide();
		}
	});
	
	//点击空白出隐藏选择器
	$(document).on("click", function(e){
		var target1  = $(e.target);
        if(target1.closest(".chose dl").length == 0){
			$(".chose dl dd").hide();
			$(".chose dl").removeClass("current");
		}
	});

	//范围确定选择2项
	$(document).on("click", "[f='but_selrange_confirm']", function(){
	
		$_data_1 = $(this).attr("data-1");
		$_data_2 = $(this).attr("data-2");
		$_data_unit = $(this).attr("data-unit");
		$_data_tips = $(this).attr("data-tips");
		if (typeof($_data_unit) == "undefined") {
			$_data_unit = "";
		}
		if (typeof($_data_tips) == "undefined") {
			$_data_tips = "";
		}
		$_val1 = $("#"+$_data_1).find("option:selected").val();
		$_text1 = $("#"+$_data_1).find("option:selected").text();
		$_val2 = $("#"+$_data_2).find("option:selected").val();
		$_text2 = $("#"+$_data_2).find("option:selected").text();

		if ($_val1 > 0 && $_val2 > 0) {
			$_text = $_text1+$_data_unit+"-"+$_text2+$_data_unit;
		}
		else {
			$_text = $_data_tips;
		}
		$(this).parent().prev().children("em").html($_text);
		$(this).parent().hide();
		$(this).parent().parent().removeClass("current");

	});

	//搜索按钮
	$(document).on("click", "[f='but_confirm_marryser']", function(){
		$("#marry_form").submit();
	});
	
	//显示隐藏详情
	$(document).on("mouseover", "[f='show_marry_more']", function(){
		$_id = $(this).attr("data-id");
		if ($("#more_"+$_id).css("display") == "none") {
			$("#more_"+$_id).fadeIn(100);
		}
	
	});
	$(document).on("mouseout", "[f='show_marry_more']", function(){
		$_id = $(this).attr("data-id");
		if ($("#more_"+$_id).css("display") == "block") {
			$("#more_"+$_id).fadeOut(100);
		}
	
	});

	//应征报名
	$(document).on("click", "[f='but_marry_bm']", function(){
		$_id = $(this).attr("data-id");
		$_obj = $(this);
		if ($_id > 0) {
			$_url = _OE_FILE+"?c=marry&a=savebm&id="+$_id;
			oeAjaxConfirmBox($_url, "确定要报名吗？", function(){
				$_obj.addClass("current");
				$_obj.html("<i></i>已经报名");
			});
		}
	});

	
	//查看图片
	$(document).on("click", "[f='but_open_marry_zoom']", function(){
		$_id = $(this).attr("data-id"); //当前marry id
		$_orderi = $(this).attr("data-orderi"); //当前图片排序

		$("body").append("<div class='page_loading' style='display:block;' id='ajax_loading'><span></span></div>");
		$("html").addClass("dialog_lock_hide");
		$.ajax({
			type: "POST",
			url: _ROOT_PATH+"index.php?c=marry",
			cache: false,
			data: {a:"zoom", id:$_id, orderi:$_orderi, datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					$("#marry_zoom_data").html($result);
					$("#marry_zoom_box").fadeIn(100, function(){
						$("html").addClass("dialog_lock_hide");
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("获取数据失败");
					}
				}
				$("#ajax_loading").remove();
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});
	});

	//关闭图片
	$(document).on("click", "[f='but_close_marry_zoom']", function(){
		$("#marry_zoom_box").fadeOut(100, function(){
			$("#marry_zoom_data").html("");
			$("html").removeClass("dialog_lock_hide");
		});
	});

	//图片 上一张
	$(document).on("click", "[f='but_prev_zomm']", function(){
		$zoom_nums = parseInt($("#zoom_nums").val()); //张数
		$orderi = parseInt($("#orderi").val()); //当前
		$prev_orderi = 0;
		if ($orderi > 1) {
			$prev_orderi = ($orderi-1);
		}
		else {
			$prev_orderi = $zoom_nums;
		}		
		if ($prev_orderi > 0) {
			$("#zoom_orderi").html($prev_orderi);
			$("#orderi").val($prev_orderi);
			
			$("#zoom_list ._list").hide();
			$("#zoom_"+$prev_orderi).show();
		}

	});
	
	//图片 下一张
	$(document).on("click", "[f='but_next_zomm']", function(){
		$zoom_nums = parseInt($("#zoom_nums").val()); //张数
		$orderi = parseInt($("#orderi").val()); //当前
		$next_orderi = 0;
		if ($orderi < $zoom_nums) {
			$next_orderi = ($orderi+1);
		}
		else {
			$next_orderi = 1;
		}
		if ($next_orderi > 0) {
			$("#zoom_orderi").html($next_orderi);
			$("#orderi").val($next_orderi);

			$("#zoom_list ._list").hide();
			$("#zoom_"+$next_orderi).show();
		}

	});

});